
#include <BSpacer>
#include "member_BSpacer.h"

using namespace BWE;

#define member					(*(member_BSpacer*)_ptr)
#define member_allocate()		_ptr = new member_BSpacer(this)
#define member_release()		delete (member_BSpacer*)_ptr

BSpacer::BSpacer(const BString& name) : BObject(name)
{
	member_allocate();
}
BSpacer::BSpacer(int width, int height, Policy widthPolicy, Policy heightPolicy)
{
	member_allocate();
	member.rect.setSize(width, height);
	member.hintSize.set(width, height);
	this->setSizePolicy(widthPolicy, heightPolicy);
}
BSpacer::~BSpacer()
{
	member_release();
}

void BSpacer::setSize(int width, int height)
{
	setSize(BSize(width, height));
}
void BSpacer::setSize(const BSize& size)
{
	BSize temp = size;
	temp.limit(member.minSize, member.maxSize);
	if (member.rect.size() != temp)
	{
		member.rect.setSize(temp);
		member.dirtyLayout();
	}
}
BSize BSpacer::size() const
{
	return member.rect.size();
}

void BSpacer::setRect(int x, int y, int width, int height)
{
	setRect(BRect(x, y, width, height));
}
void BSpacer::setRect(const BRect& rect)
{
	if (member.rect != rect)
	{
		member.rect.setPos(rect.pos());
		BSize size = rect.size();
		size.limit(member.minSize, member.maxSize);
		if (member.rect.size() != size)
		{
			member.rect.setSize(size);
		}
		member.dirtyLayout();
	}
}
const BRect& BSpacer::rect() const
{
	return member.rect;
}

void BSpacer::setSizeHint(const BSize& hintSize)
{
	if (member.hintSize != hintSize)
	{
		member.hintSize = hintSize;
		member.dirtyLayout();
	}
}
const BSize& BSpacer::sizeHint() const
{
	return member.hintSize;
}

void BSpacer::setFixedSize(const BSize& fixedSize)
{
	if (member.fixedSize != fixedSize)
	{
		member.fixedSize = fixedSize;
		member.dirtyLayout();
	}
}
BSize BSpacer::fixedSize() const
{
	return member.fixedSize;
}

void BSpacer::setMinSize(const BSize& minSize)
{
	if (member.minSize != minSize)
	{
		member.minSize = minSize;
		member.dirtyLayout();
	}
}
const BSize& BSpacer::minSize() const
{
	return member.minSize;
}

void BSpacer::setMaxSize(const BSize& maxSize)
{
	if (member.maxSize != maxSize)
	{
		member.maxSize = maxSize;
		member.dirtyLayout();
	}
}
const BSize& BSpacer::maxSize() const
{
	return member.maxSize;
}

void BSpacer::setSizePolicy(Policy widthPolicy, Policy heightPolicy)
{
	setSizePolicy(BSizePolicy(widthPolicy, heightPolicy));
}
void BSpacer::setSizePolicy(const BSizePolicy& sizePolicy)
{
	if (member.sizePolicy != sizePolicy)
	{
		member.sizePolicy = sizePolicy;
		if (sizePolicy.widthPolicy() == Policy_Fixed)
			member.fixedSize.width() = member.rect.width();
		if (sizePolicy.heightPolicy() == Policy_Fixed)
			member.fixedSize.height() = member.rect.height();
		member.dirtyLayout();
	}
}
const BSizePolicy& BSpacer::sizePolicy() const
{
	return member.sizePolicy;
}

void BSpacer::setSizeStretch(float sizeStretch)
{
	if (member.sizeStretch != sizeStretch)
	{
		member.sizeStretch = sizeStretch;
		member.dirtyLayout();
	}
}
float BSpacer::sizeStretch() const
{
	return member.sizeStretch;
}
